{{- define "monitoring_ping_resources" }}
cpu: 25m
memory: 50Mi
{{- end }}

{{- if (.Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
---
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: monitoring-ping
  namespace: d8-monitoring
  {{- include "helm_lib_module_labels" (list . (dict "app" "monitoring-ping" "workload-resource-policy.deckhouse.io" "every-node")) | nindent 2 }}
spec:
  targetRef:
    apiVersion: "apps/v1"
    kind: DaemonSet
    name: monitoring-ping
  updatePolicy:
    updateMode: "Auto"
  resourcePolicy:
    containerPolicies:
    - containerName: "monitoring-ping"
      minAllowed:
        {{- include "monitoring_ping_resources" . | nindent 8 }}
      maxAllowed:
        cpu: 50m
        memory: 50Mi
{{- end }}
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: monitoring-ping
  namespace: d8-monitoring
  {{- include "helm_lib_module_labels" (list . (dict "app" "monitoring-ping")) | nindent 2 }}
spec:
  updateStrategy:
    type: RollingUpdate
  selector:
    matchLabels:
      name: monitoring-ping
  template:
    metadata:
      labels:
        name: monitoring-ping
        app: monitoring-ping
    spec:
      terminationGracePeriodSeconds: 0
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet
      {{- include "helm_lib_priority_class" (tuple . "cluster-medium") | nindent 6 }}
      {{- include "helm_lib_tolerations" (tuple . "any-node") | nindent 6 }}
      {{- include "helm_lib_module_pod_security_context_run_as_user_deckhouse" . | nindent 6 }}
      serviceAccountName: monitoring-ping
      containers:
      - image: {{ include "helm_lib_module_image" (list . "monitoringPing") }}
        name: monitoring-ping
        {{- /*
          UID: 0 GID:0 using for privilege access for fping because using hostNetwork
        */}}
        securityContext:
          allowPrivilegeEscalation: true
          capabilities:
            add:
            - NET_RAW
            - DAC_OVERRIDE
            drop:
            - ALL
          readOnlyRootFilesystem: true
          runAsGroup: 0
          runAsNonRoot: false
          runAsUser: 0
        env:
          - name: MY_NODE_NAME
            valueFrom:
              fieldRef:
                fieldPath: spec.nodeName
          - name: PROMETHEUS_TEXTFILE_DIR
            value: /node-exporter-textfile/
          - name: PROMETHEUS_TEXTFILE_PREFIX
            value: monitoring-ping_
        volumeMounts:
          - name: textfile
            mountPath: /node-exporter-textfile
          - name: config
            mountPath: /config
        resources:
          requests:
            {{- include "helm_lib_module_ephemeral_storage_logs_with_extra" 10 | nindent 12 }}
{{- if not ( .Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
            {{- include "monitoring_ping_resources" . | nindent 12 }}
{{- end }}
      volumes:
        - name: textfile
          hostPath:
            path: /var/run/node-exporter-textfile
        - name: config
          configMap:
            name: monitoring-ping-config
      imagePullSecrets:
      - name: deckhouse-registry
